package com.wmx.springsession.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**********************************
 * @author wmx
 * @date 2019/11/5 16:41
 * @description:
 * @version 1.0
 ************************************/
@RestController
@RequestMapping("/sys/session/")
public class SpringSessionController {

    @GetMapping("getSession")
    public  Map<String, Object> getSession(HttpServletRequest request){
        request.getSession().setAttribute("username", "admin");
        Map<String, Object> map = new HashMap<>();
        map.put("sessionId", request.getSession().getId());
        return map;
    }

    @GetMapping("get")
    public String get(HttpServletRequest request){
        return (String) request.getSession().getAttribute("username");
    }
}
